<?php
defined('BASEPATH') OR exit('No direct script access allowed');



class AdminBase extends CI_Controller{
    
    
    public function __construct(){
        parent::__construct();
        $this->load_lang();
        $this->load->helper('common');
        $this->checklog();
        $this->router->class;
       
    }
    
    private function load_lang(){
        $this->load->helper('language');
        $lang_key = $this->config->item('language');
        $this->lang->load($lang_key,$lang_key);
    }
    
    private function checklog(){
        
        $url_router     =  strtolower($this->router->class."/".$this->router->method);
        $user_session   = get_user_session();
        $source_arr     = explode("/",str_replace("http://","", @$_SERVER['HTTP_REFERER']),2);
        $this->load->vars('user_info',$user_session);
        $this->load->vars('url_router',$url_router);
        $this->load->vars('url_source',@$source_arr[1]);
        
        if(!in_array($url_router, ['admin/login','admin/logout'])){
            if(!$user_session)
            {
                jump('/admin/login');
            }
        }
        
        if($url_router === 'admin/login')
        {
            if($user_session)
            {
                jump('/admin/index');
            }
        }
        
    }
}